Don't fail `cargo login` if `~/.cargo` doesn't exist
authorAlex Crichton <alex@alexcrichton.com>
Fri, 21 Nov 2014 03:14:58 +0000 (19:14 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 25 Nov 2014 02:18:52 +0000 (18:18 -0800)
Closes #927

src/cargo/util/config.rs
tests/test_cargo_registry.rs

index 07e4938efa520cbc2961fc91bad63f51625a82f1..c7f0703889dbe849581671b89d012f05072bf6c4 100644 (file)
@@ -1,7 +1,8 @@
 use std::{fmt, os, mem};
 use std::cell::{RefCell, RefMut};
 use std::collections::hash_map::{HashMap, Occupied, Vacant};
-use std::io::fs::{PathExtensions, File};
+use std::io;
+use std::io::fs::{mod, PathExtensions, File};
 use std::string;
 
 use serialize::{Encodable,Encoder};
@@ -344,6 +345,7 @@ pub fn set_config(cfg: &Config, loc: Location, key: &str,
         Location::Global => cfg.home_path.join(".cargo").join("config"),
         Location::Project => unimplemented!(),
     };
+    try!(fs::mkdir_recursive(&file.dir_path(), io::USER_DIR));
     let contents = File::open(&file).read_to_string().unwrap_or("".to_string());
     let mut toml = try!(cargo_toml::parse(contents.as_slice(), &file));
     toml.insert(key.to_string(), value.into_toml());
index a9aa06f168948e72c36e1539b3568ab38e41c69b..3fc4f7f8eb32b3ffe26548508f45668e7815b1de 100644 (file)
@@ -1,4 +1,5 @@
-use std::io::{fs, File};
+use std::io::{mod, fs, File};
+use cargo::util::process;
 
 use support::{project, execs, cargo_dir};
 use support::{UPDATING, DOWNLOADING, COMPILING, PACKAGING, VERIFYING};
@@ -469,3 +470,13 @@ test!(dev_dependency_not_used {
 ", updating = UPDATING, downloading = DOWNLOADING, compiling = COMPILING,
    dir = p.url()).as_slice()));
 })
+
+test!(login_with_no_cargo_dir {
+    let home = paths::home().join("new-home");
+    fs::mkdir(&home, io::USER_DIR).unwrap();
+    assert_that(process(cargo_dir().join("cargo")).unwrap()
+                       .arg("login").arg("foo").arg("-v")
+                       .cwd(paths::root())
+                       .env("HOME", Some(home)),
+                execs().with_status(0));
+})